# encoding: UTF-8
 
class Admin::EventsController < ApplicationController
  
  before_filter :user_signed_in?
  
  def index
    @events = Event.all
    set_seo_meta '活动专题'
  end

  def new
    @esort = Esort.open_status
    set_seo_meta '增加活动专题'
  end
  
  def create
    @event = Event.new(params[:session])
    if @event.save!
      redirect_to events_path, notice: '新增成功!'
    else
      redirect_referrer_or_default default
    end  
  end

  def edit
    @esort = Esort.open_status
    @event = Event.find(params[:id]) 
    set_seo_meta '内容修改'
  end

  def update
    @event = Event.find(params[:id])
    if @event.update_attributes!(params[:session])
      redirect_to events_path, notice:'修改成功'
    else
      redirect_referrer_or_defautl default
    end
  end

  def destroy
    if Event.delete(params[:id])
      redirect_to events_path, notice:'删除成功'
    else
      redirect_referrer_or_default default
    end  
  end

end
